<?php
class Zendvn_File_Upload extends Zend_File_Transfer_Adapter_Http{
	
	/*
	 * $options['rename'] = true
	 * $options['prefix'] = pic_
	 */
	public function upload($destination = null, $file_upload = null, $options = null){
		$this->setDestination($destination,$file_upload);
		
		$newFile = $this->getFileName($file_upload,false);
		
		if($options['rename'] == true){
			$fileName = $this->getFileName($file_upload,false);			
			$tmp = preg_match('#\.[^.]+$#', $fileName,$match);			
			$newFile = $options['prefix'] . time() . $match[0];			
			$this->addFilter('Rename',array('target'=>$newFile),$file_upload);
		}
		
		$this->receive($file_upload);
		
		return $newFile;
	}
	
	public function remove($destination = null, $file_name = null){
		
		$filter = new Zend_Filter_PregReplace(array('match'=>'#[/]{2,}#','replace'=>'/'));
		$removeFile = $destination . '/' . $file_name;
		$removeFile = $filter->filter($removeFile);
		@unlink($removeFile);
		
	}
	
}